//
//  DataListTableView.m
//  SocketTelnet
//
//  Created by Hur Song on 13. 1. 2..
//  Copyright (c) 2013년 song. All rights reserved.
//

#import "DataListTableView.h"

@implementation DataListCell
@synthesize lableText = _lableText;

@end

@implementation DataListTableView

@synthesize dataList = _dataList;
@synthesize dataDelegate = _dataDelegate;


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

+ (id)dataListTableViewController:(NSMutableArray *)list
{
	DataListTableView * controller = [[DataListTableView alloc] initWithNibName:@"DataListTableView" bundle:nil];
	controller.dataList = list;
	return controller;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [_dataList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
	NSString * listText = (NSString*)[_dataList objectAtIndex:indexPath.row];
	NSArray * listArray = [listText componentsSeparatedByString:@" "];
    cell.textLabel.text = [listArray objectAtIndex:listArray.count-1];

	if ([[listText substringToIndex:1] isEqualToString:@"d"] == YES)
		cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	else
		cell.accessoryType = UITableViewCellAccessoryNone;

    
    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell.accessoryType == UITableViewCellAccessoryDisclosureIndicator)
	{
		[_dataDelegate handleChangeDirectory:cell.textLabel.text];
	}
}

@end
